home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / g__~1 / gplibs15.zoo / gnulib3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-05  |  1.6 KB  |  74 lines

  1. /*
  2.  * very important: for the atari keep  this file 16/32 bit int clean
  3.  *    ++jrb
  4.  */
  5.  
  6. #ifndef NO_GNULIB3  /* skip entire file if NO_GNULIB3 */
  7.  
  8. #ifdef atarist
  9. #include <stdlib.h>
  10. #endif
  11.  
  12. /*  Declare a pointer to void function type.  */
  13.  
  14. typedef void (*func_ptr) (void);
  15.  
  16. /* Declare the set of symbols use as begin and end markers for the lists
  17.    of global object constructors and global object destructors.  */
  18.  
  19. extern func_ptr __CTOR_LIST__[];
  20. extern func_ptr __DTOR_LIST__[];
  21.  
  22. int atexit (void (*) (void));
  23. static void __do_global_dtors ();
  24. static void __do_global_ctors ();
  25.  
  26. void
  27. __main ()
  28. {
  29.     /* Support recursive calls to `main': run initializers just once.  */
  30.     static short initialized = 0;
  31.     if (! initialized)
  32.     {
  33.     initialized = 1;
  34.     __do_global_ctors ();
  35.     }
  36. }
  37.  
  38. /* Run all global constructors on entry to program, setup to run destructors
  39.    at exit.
  40. */
  41. static void
  42. __do_global_ctors ()
  43. {
  44.     func_ptr *p;
  45.     for (p = __CTOR_LIST__ + 1; *p; )
  46.     (*p++) ();
  47.  
  48.     atexit(__do_global_dtors);
  49. }
  50.  
  51. /* Run all the global destructors on exit from the program.  */
  52.  
  53. static void
  54. __do_global_dtors ()
  55. {
  56.     long nptrs = *(long *)__DTOR_LIST__;
  57.     long i;
  58.  
  59.     /* Some systems place the number of pointers
  60.        in the first word of the table.
  61.        On other systems, that word is -1.
  62.        In all cases, the table is null-terminated.  */
  63.  
  64.     /* If the length is not recorded, count up to the null.  */
  65.     if (nptrs == -1)
  66.     for (nptrs = 0; __DTOR_LIST__[nptrs + 1] != 0; nptrs++);
  67.  
  68.     /* GNU LD format.  */
  69.     for (i = nptrs; i >= 1; i--)
  70.     __DTOR_LIST__[i] ();
  71. }
  72.  
  73. #endif /* NO_GNULIB3 */
  74.